package com.cskaoyan.controller;

import com.cskaoyan.bean.PO.MarketGoods;
import com.cskaoyan.bean.PO.MarketTopic;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.WxTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * @Description:
 * @author:刘杰
 * @create: 2022-08-17 21:04
 */
@RestController
@RequestMapping("/wx/topic")
public class WxTopicController {
    @Autowired
    WxTopicService wxTopicService;


    @GetMapping("/detail")
    public BaseRespVo detail(Integer id) {
        Map<String, Object> detail = wxTopicService.read(id);
        List<MarketGoods> goodsList = (List<MarketGoods>) detail.remove("goodsList");
        detail.put("goods", goodsList);
        return BaseRespVo.ok(detail);
    }

    @GetMapping("/related")
    public BaseRespVo related(Integer id) {

        CommonData<MarketTopic> commonData = wxTopicService.related(id);

        return BaseRespVo.ok(commonData);
    }


    @GetMapping("/list")
    public BaseRespVo list(BasePageInfo pageInfo) {

        pageInfo.setSort("add_time");
        pageInfo.setOrder("desc");
        CommonData<MarketTopic> commonData = wxTopicService.list(pageInfo, null, null);
        return BaseRespVo.ok(commonData);
    }
}
